import logging
from datetime import timedelta

from redis import StrictRedis


class Config(object):
    """
    项目的配置
    """
    # 开发者模式的配置
    DEBUG = True
    SECRET_KEY = 'jfjgjfigafjg'

    # 数据库的相关配置
    SQLALCHEMY_DATABASE_URI = 'mysql://root:512279csx@127.0.0.1:3306/news'
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # redis 数据库配置
    redis_host = '127.0.0.1'
    redis_post = 6379
    # csrf保护配置

    # Session 配置
    # 保存session 的方式，
    SESSION_TYPE = 'redis'

    SESSION_REDIS =StrictRedis(host=redis_host,port=redis_post)
    # session key 的前缀
    SESSION_KEY_PREFIX = 'news'
    # 是否使用用户签名
    SESSION_USE_SIGNER = True
    # session保存的时间
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)

    """
    self.redis.setex(name=self.key_prefix + session.sid, value=val,
                         time=total_seconds(app.permanent_session_lifetime))
    """
    # 日志的等级
    log_level = logging.DEBUG
class DevelopConfig(Config):
    """
    开发者模式配置
    """
    DEBUG = True
class ProductConfig(Config):
    DEBUG = False
    log_level = logging.ERROR

config = {
    'dev':DevelopConfig,
    'pro':ProductConfig
}